namespace LanSunERP
{
    using System;
    using System.ServiceModel;
    using System.Windows.Forms;
    using System.Diagnostics;
    using System.Collections.Generic;
    using System.Runtime.Serialization;
    using System.Collections;
    using System.Data;
    using System.Data.SqlClient;

    public class SysKeyData : QueryCommand
    {
        public SysKeyData() : base() { }
        public SysKeyData(SqlCommand cmdSQL, DataTable dtRequest, string RequestJob)
            : base(cmdSQL, dtRequest, RequestJob) { }
        public SqlCommand BuildCommand()
        {

            switch (RequestJob.Substring(6,10))
            {
                case "0000000000": 
                /*
                     case "SysKeyData":
                        SysKeyData m_SysKeyData = new SysKeyData(cmdSQL, dtRequest, RequestJob);
                        cmdSQL = m_SysKeyData.BuildCommand();
                        break;
                */
                    break;
                case "1000000000": 
                    break;
                 case "2000000001":
                 case "4000000000":
                    cmdSQL.Parameters.Add(new SqlParameter("@InstanceID", dwRequest["InstanceID"].ToString()));
                    break; 
                case "1000007374":  //IX_SysKeyData
                  cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));  
                  cmdSQL.Parameters.Add(new SqlParameter("@KeyCondition", dwRequest["KeyCondition"].ToString()));  
                    break;
                case "1000007376":  //IX_SysKeyData_Key
                  cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));  
                  cmdSQL.Parameters.Add(new SqlParameter("@KeyCondition", dwRequest["KeyCondition"].ToString()));  
                    break;
                case "1000007381":  //IX_SysKeyData_SysID
                  cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));  
                    break;
                case "1000007383":  //TX_SysKeyData
                  cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));  
                  cmdSQL.Parameters.Add(new SqlParameter("@KeyCondition", dwRequest["KeyCondition"].ToString()));  
                    break;
               case "2000000000": 
               case "3000000001":
               case "3000000000":
                    cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@InstanceID", dwRequest["InstanceID"].ToString()));
                    cmdSQL = BuildInstanceKey(cmdSQL, dwRequest);
                    cmdSQL.Parameters.Add(new SqlParameter("@KeyName", dwRequest["KeyName"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@KeyDes", dwRequest["KeyDes"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@KeyCondition", dwRequest["KeyCondition"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@LongDes", dwRequest["LongDes"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@ShortDes", dwRequest["ShortDes"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@CurrentValue", dwRequest["CurrentValue"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@StepSize", dwRequest["StepSize"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@MaxValue", dwRequest["MaxValue"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@UpperInstanceID", dwRequest["UpperInstanceID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@KeyControllingRulesID", dwRequest["KeyControllingRulesID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@PositionID", dwRequest["PositionID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@LastPositionID", dwRequest["LastPositionID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@SubStatus", dwRequest["SubStatus"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@Status", dwRequest["Status"].ToString()));
                    break;
            }
            return cmdSQL;

        }
        public override SqlCommand BuildInstanceKey(SqlCommand cmdSQL, DataRow dwTemp)
        { 
                string InstanceKey = dwTemp["InstanceKey"].ToString().Trim();
                    string SysID=dwTemp["SysID"].ToString().Trim();
                    string KeyCondition=dwTemp["KeyCondition"].ToString().Trim();
           
            {
                if (SysID!=""&&KeyCondition!="")
                {
                    InstanceKey =SysID+"."+KeyCondition;
                    dwTemp["InstanceKey"] = InstanceKey;
                    dwTemp.AcceptChanges();
                }
            }
            cmdSQL.Parameters.Add(new SqlParameter("@InstanceKey", dwRequest["InstanceKey"].ToString()));
            return base.BuildInstanceKey(cmdSQL, dwTemp);
        }
}
 public class SysKeyDataQueryCond : QueryCommand
    {
        public SysKeyDataQueryCond() : base() { }
        public SysKeyDataQueryCond(SqlCommand cmdSQL, DataTable dtRequest, string RequestJob)
         : base(cmdSQL, dtRequest,RequestJob) {  }

        public SqlCommand BuildCommand()
        {
            switch (RequestJob.Substring(6,10))
            {
                case "0000000000": break;
                case "1000000000": break;
                case "1000000001": break;
                case "1000000002": break;
                case "2000000000": 
                case "3000000000":
                    cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@InstanceID", dwRequest["InstanceID"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@InstanceKey", dwRequest["InstanceKey"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@KeyName", dwRequest["KeyName"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@KeyDes", dwRequest["KeyDes"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@KeyCondition", dwRequest["KeyCondition"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@LongDes", dwRequest["LongDes"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@ShortDes", dwRequest["ShortDes"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@CurrentValue", dwRequest["CurrentValue"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@StepSize", dwRequest["StepSize"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@MaxValue", dwRequest["MaxValue"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@UpperInstanceID", dwRequest["UpperInstanceID"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@KeyControllingRulesID", dwRequest["KeyControllingRulesID"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@PositionID", dwRequest["PositionID"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@LastPositionID", dwRequest["LastPositionID"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@SubStatus", dwRequest["SubStatus"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@Status", dwRequest["Status"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@FrstUser", dwRequest["FrstUser"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@FrstDate", dwRequest["FrstDate"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@LastUser", dwRequest["LastUser"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@LastDate", dwRequest["LastDate"].ToString()));
                
                    break;
                case "4000000000":
                    cmdSQL.Parameters.Add(new SqlParameter("@InstanceID", dwRequest["InstanceID"].ToString())); 
                    break;
            }
             return cmdSQL;

        }      

    }
 }
 
